package cn.itcast.service.impl;

import cn.itcast.dao.CourierDao;
import cn.itcast.domain.Courier;
import cn.itcast.service.CourierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class CourierServiceImpl implements CourierService {

    @Autowired
    private CourierDao courierDao;


    @Override
    public void save(Courier courier) {
        courierDao.save(courier);
    }

    @Override
    public Page<Courier> queryPage(PageRequest pageable) {
        return courierDao.findAll(pageable);
    }


    @Override
    public void delBatch( String[] idArray) {
        for (String idStr : idArray) {
            //将id装换为int类型
            Integer id = Integer.parseInt(idStr);
            //调用Dao层方法
            courierDao.delInBatch(id);
        }
    }

    @Override
    public void resBatch(String[] idArray) {
        for (String idStr : idArray) {
            //将id转换为int类型
            Integer id = Integer.parseInt(idStr);
            //调用dao方法
            courierDao.resBatch(id);
        }
    }

    @Override
    public void activeBatch(String[] idArray) {
        for (String idStr : idArray) {
            //将id转换为int类型
            Integer id = Integer.parseInt(idStr);
            //调用dao方法
            courierDao.activeBatch(id);
        }
    }

}
